package com.stylefeng.guns.modular.hhtb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.modular.hhtb.model.LogPurseCorpusDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.hhtb.model.LogPurseCorpus;
import com.stylefeng.guns.modular.hhtb.service.ILogPurseCorpusService;

import java.util.List;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-08-30 09:49:55
 */
@Controller
@RequestMapping("/logPurseCorpus")
public class LogPurseCorpusController extends BaseController {

    private String PREFIX = "/hhtb/logPurseCorpus/";

    @Autowired
    private ILogPurseCorpusService logPurseCorpusService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "logPurseCorpus.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/logPurseCorpus_add")
    public String logPurseCorpusAdd() {
        return PREFIX + "logPurseCorpus_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/logPurseCorpus_update/{logPurseCorpusId}")
    public String logPurseCorpusUpdate(@PathVariable Integer logPurseCorpusId, Model model) {
        LogPurseCorpus logPurseCorpus = logPurseCorpusService.selectById(logPurseCorpusId);
        model.addAttribute("item",logPurseCorpus);
        LogObjectHolder.me().set(logPurseCorpus);
        return PREFIX + "logPurseCorpus_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(LogPurseCorpusDto logPurseCorpusDto) {
        Page<LogPurseCorpusDto> page = new PageFactory<LogPurseCorpusDto>().defaultPage();
        List<LogPurseCorpusDto> list = logPurseCorpusService.showLogPurseCorpusInfo(page,logPurseCorpusDto);
        page.setRecords(list);
        return super.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LogPurseCorpus logPurseCorpus) {
        logPurseCorpusService.insert(logPurseCorpus);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer logPurseCorpusId) {
        logPurseCorpusService.deleteById(logPurseCorpusId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LogPurseCorpus logPurseCorpus) {
        logPurseCorpusService.updateById(logPurseCorpus);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{logPurseCorpusId}")
    @ResponseBody
    public Object detail(@PathVariable("logPurseCorpusId") Integer logPurseCorpusId) {
        return logPurseCorpusService.selectById(logPurseCorpusId);
    }
}
